package com.aote.entity.model;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.aote.model.DataShowTableModel;
import com.browsesoft.Entity;
import com.browsesoft.baseadapter.AdvancedSimpleEntity;

/**
 * 实体属性表格模型
 */
public class EntityAttributeTableModel extends DataShowTableModel {
	/**
	 * 属性列表的名字
	 */
	private String property;

	/**
	 * 
	 */
	public void init(HttpServletRequest request) throws Exception {
		super.init(request);
		this.property = this.component.getElement().getAttribute("property");
	}

	protected void setDatas(HttpServletRequest request) {
		this.datas = this.getData(request);
	}

	private List getData(HttpServletRequest request) {
		// 从父对象里得到本属性的子对象列表
		AdvancedSimpleEntity entity = (AdvancedSimpleEntity) this.component
				.getParent().getModel();
		List entities = entity.getPartEntities(this.property);
		// 把对象列表转换成对象属性列表
		List result = new LinkedList();
		if (entities == null) {
			return result;
		}
		Iterator iter = entities.iterator();
		while (iter.hasNext()) {
			Entity e = (Entity) iter.next();
			// 对选择结果设置属性
			result.add(e.getAttributes());
		}
		return result;
	}
}